<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="tree-card">
        <!-- 用了一个行列布局 -->
        <TreeTools :tree-node="company" :istoop="true" @addDepartments="addDepartments" />
        <hr>
        <!-- 以上是头部的公司信息 -->
        <!-- :default-expand-all="true" 默认展开 -->
        <el-tree :data="departs" :props="{label:'name'}" :default-expand-all="false" class="tree">
          <!-- 作用域插槽需要指定两个东西
          1. 插槽名字
          2. 接收数据的形参 -->
          <template #default="scoped">
            <TreeTools :tree-node="scoped.data" :istoop="false" @editDepartment="editDepartment" @deletedatabase="getDepartments" @addDepartments="addDepartments" />
          </template>
        </el-tree>
      </el-card>
      <!-- 相同名字不影响 -->
      <!-- @addDepartments="getDepartments"  -->
      <!-- 接收子组件的请求 -->
      <!-- :show-dialog.sync="showDialog" -->
      <!-- vuejs提供的一种方法 子传父就不需要@了 -->
      <!-- 直接在 :show-dialog后面. sync 就可以实现传值了、-->
      <Adddepet ref="addDept" :tree="treeNode" :show-dialog.sync="showDialog" @addDepartments="getDepartments" />

    </div>
  </div>
</template>

<script>
import Adddepet from './components/add-dept'
import { Fixthebrokenarray } from '@/utils/index'
import { getDepartments } from '@/api/depaartments'
import TreeTools from './components/TreeTools '
export default {
  components: {
    TreeTools,
    Adddepet
  },
  data() {
    return {
      id: '',
      treeNode: {},
      showDialog: false,
      company: {
        name: '江苏传智播客教育科技股份有限公司',
        manager: '负责人'
      },
      departs: []
    }
  },
  // 钩子函数页面加载调用一次
  created() {
    this.getDepartments()
  },
  methods: {
    // 更新列表信息
    async getDepartments() {
      const res = await getDepartments()
      console.log('res', res)
      this.departs = Fixthebrokenarray(res.depts, '')
    },
    addDepartments(treeNode) {
      console.log('treeNode', treeNode)

      this.showDialog = true
      this.treeNode = treeNode
    },
    // 弹出框显示
    // memits() {
    //   this.showDialog = false
    // }
    // 当前点击的
    editDepartment(treeNode) {
      this.showDialog = true
      this.treeNode = treeNode
      // 直接调用子组件的函数
      this.$refs.addDept.getDepartmentDetail(treeNode.id)
    }
  }

}
</script>

<style scoped>
.tree-card {
  padding: 30px  140px;
  font-size:20px;
}
.el-dropdown-selfdefine{
  font-size:20px;
}

</style>
